<template>
<el-container>
  <el-header>
    <doreminav></doreminav>
  </el-header>
  <el-container>
    <div class="box" ref="box">
      <div class="left">
          <!-- <el-aside :width=asideWidth class="left"> -->
            <doremiuntree @func="getUntree"></doremiuntree>
          <!-- </el-aside> -->
      </div>
      <div class="resize" title="收缩侧边栏">
          ⋮
      </div>
      <div class="mid">
          <!-- <el-main class="mid"> -->
            <keep-alive>
              <doremIframe :msg=treeData></doremIframe>
            </keep-alive>
          <!-- </el-main> -->
      </div>
    </div>
  </el-container>
</el-container>
</template>
<script>
  import nav from "../components/doremi/NavMunu"
  // import untree from "../demo/elTree"
  import untree from "../components/doremi/lazyEltree"
  import iframe from "../components/doremi/iframe"
  export default {
    components:{
      doreminav:nav,
      doremIframe:iframe,
      doremiuntree:untree
    },
    data() {
      return{
        treeData:{},
        asideWidth:"300px"
      }

    },
    created(){

    },
    methods:{
      getUntree(data){
        this.treeData=data
        // console.log("index"+data.id)
      },
      // changeAside() {
      //   this.asideWidth = '400px'  //修改成功，这种方式相当于直接修改html上的值，会重新渲染
      // }
      dragControllerDiv: function () {
        var resize = document.getElementsByClassName('resize');
        console.log(resize)
        var left = document.getElementsByClassName('left');
        var mid = document.getElementsByClassName('mid');
        var box = document.getElementsByClassName('box');
        // for (let 0 = 0; 0 < resize.length; 0++) {
            // 鼠标按下事件
            resize[0].onmousedown = function (e) {
                //颜色改变提醒
                resize[0].style.background = '#818181';
                var startX = e.clientX;
                console.log(resize[0].offsetLeft)
                console.log(startX)
                resize[0].left = resize[0].offsetLeft;
                // console.log(resize[0].left)
                // 鼠标拖动事件
                document.onmousemove = function (e) {
                    var endX = e.clientX;
                    var leftWidth = resize[0].left + (endX - startX); // （endx-startx）=移动的距离。resize[0].left+移动的距离=左边区域最后的宽度
                    var rightWidth = box[0].clientWidth - resize[0].offsetWidth; // 容器宽度 - 左边区域的宽度 = 右边区域的宽度

                    if (leftWidth < 150){
                        leftWidth = 150; // 左边区域的最小宽度为32px
                    } 
                    
                    if (leftWidth > rightWidth - 150){
                        leftWidth = rightWidth - 150; //右边区域最小宽度为150px
                    } 
                    resize[0].style.left = leftWidth; // 设置左侧区域的宽度

                    // for (let 0 = 0; 0 < left.length; 0++) {
                        left[0].style.width = leftWidth + 'px';
                        mid[0].style.width = (box[0].clientWidth - leftWidth - 10) + 'px';
                    // }
                };
                // 鼠标松开事件
                document.onmouseup = function (evt) {
                    //颜色恢复
                    resize[0].style.background = '#d6d6d6';
                    document.onmousemove = null;
                    document.onmouseup = null;
                    resize[0].releaseCapture && resize[0].releaseCapture(); //当你不在需要继续获得鼠标消息就要应该调用ReleaseCapture()释放掉
                };
                resize[0].setCapture && resize[0].setCapture(); //该函数在属于当前线程的指定窗口里设置鼠标捕获
                return false;
            // };
        }
      },
      
    },
    mounted () {
      this.dragControllerDiv();
    },
  }
</script>

<style scoped>
  /* .el-header, .el-footer {
    background-color: #B3C0D1;
    color: #333;
    text-align: center;
    padding:0;
  }
  
  .el-aside {
    background-color: #D3DCE6;
    color: #333;
    text-align: center;
  }
  
  .el-main {
    color: #333;
    text-align: center;
  }
  
  body > .el-container {
    margin-bottom: 40px;
  }
  #iframeContain{
  background: yellowgreen;
  width: 100%;
  height: 800px;
} */
</style>
<style scoped>
/* 拖拽相关样式 */
    /*包围div样式*/
    .box {
        width: 100%;
        height: 100%;
        margin: 1% 0px;
        overflow: hidden;
        box-shadow: -1px 9px 10px 3px rgba(0, 0, 0, 0.11);
    }
    /*左侧div样式*/
    .left {
        width: calc(32% - 10px);  /*左侧初始化宽度*/   
        height: 100%;
        /* height: 40px; */
        background:yellowgreen;
        float: left;
    }
    /*拖拽区div样式*/
    .resize {
        cursor: col-resize;
        float: left;
        position: relative;
        top: 45%;
        background-color: #d6d6d6;
        border-radius: 5px;
        margin-top: -10px;
        width: 10px;
        height: 50px;
        background-size: cover;
        background-position: center;
        /*z-index: 99999;*/
        font-size: 32px;
        color: white;
    }
    /*拖拽区鼠标悬停样式*/
    .resize:hover {
        color: #444444;
        height: 100%;
    }
    /*右侧div'样式*/
    .mid {
        float: left;
        width: 68%;   /*右侧初始化宽度*/
        /* height: 40px; */
        /* background: rgb(228, 110, 110); */
        /* box-shadow: -1px 4px 5px 3px rgba(0, 0, 0, 0.11); */
    }
</style>



